package hashcode;

import org.junit.jupiter.api.Test;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author : ZhuQi
 * @version : 时间:2022/7/11 9:56 版本:
 */
public class StringHashCode {

    /**
     * 测试内容: char + int 计算
     * 测试结果:
     */
    @Test
    public void should_return_int_value_when_calcCharArray_given_abc() throws Exception {
        String str = new String("abc");
        char[] chars = str.toCharArray();
        // char a = asc码 97  ； 97 + 1 = 98
        int num = chars[0] + 1;
        System.out.println(num);

    }

    /**
     * 测试内容: 测试 字符串 abc 的hashCode
     * 测试结果: 96354
     */
    @Test
    public void should_return_96354_when_calcStringHashCode_given_abc() throws Exception {
        String str = "abc";
        char[] chars = str.toCharArray();
        int h = 0;
        for (int i = 0; i < chars.length; i++) {
            h = 31 * h + chars[i];
        }
        System.out.println(h);
        System.out.println(str.hashCode());
    }

    @Test
    public void should_return_intvalue_when_calcHashMapMaxCapacity() {
        int i = 1 << 30;
        System.out.println(i);
    }

    /**
     * 测试内容:
     * 测试结果:
     */
    @Test
    public void test() throws Exception {
        ConcurrentHashMap<String, String> map =
                new ConcurrentHashMap<>(64,0.5F, 36);
        String put = map.put("1", "1");
        System.out.println(put);
    }
}
